package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.model.vo.IndexCategoryVo;
import com.atguigu.gmall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 对接后台管理系统，/admin/product相关请求
 */

@RequestMapping("/admin/product")
@RestController
public class CategoryAdminController {

    @Autowired
    CategoryService categoryService;


    @GetMapping("/getAllCategorys")
    public List<IndexCategoryVo> getAllCategorysForIndexHtml(){

        return categoryService.getAllCategorysForIndexHtml();
    }


    /**
     * 获取一级分类信息
     * @return
     */
    @GetMapping("/getCategory1")
    public Result<List<BaseCategory1>> getCategory1(){


        List<BaseCategory1> category1s =  categoryService.getCategory1();

        return Result.ok(category1s);
    }


    @GetMapping("/getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(@PathVariable("category1Id") Long category1Id){
        if(category1Id > 0){
            List<BaseCategory2> category2s = categoryService.getCategory2(category1Id);
            return Result.ok(category2s);
        }else {
            return Result.build(null, ResultCodeEnum.SECKILL_ILLEGAL);
        }
    }

    @GetMapping("/getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(@PathVariable("category2Id") Long category2Id){
        if(category2Id > 0){
            List<BaseCategory3> category3s = categoryService.getCategory3(category2Id);
            return Result.ok(category3s);
        }else {
            return Result.build(null, ResultCodeEnum.SECKILL_ILLEGAL);
        }
    }



}
